package com.gxa.p2p.controller;

import com.gxa.p2p.common.JsonResult;
import com.gxa.p2p.pojo.Repayrecord;
import com.gxa.p2p.service.RepaymentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.*;

/**
 * @author Bei
 * @date 2021/10/26 0:11
 */

@CrossOrigin
@RestController
@RequestMapping("/repayment")
@Api(value = "投资记录的接口")
public class RepaymentController {

    @Autowired
    RepaymentService repaymentService;

    /**
     * 廖泓宇
     * @return
     */
    @RequestMapping(value = "/findRepay",method = RequestMethod.POST)
    @ApiOperation("还款管理全查（可条件模糊）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "borrowName", value = "借款方名字", required = false, dataType = "String"),
            @ApiImplicitParam(name = "phone", value = "借款方手机号", required = false, dataType = "String"),
            @ApiImplicitParam(name = "page", value = "页码", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "size", value = "记录数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "state1", value = "状态1", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "state2", value = "状态2", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "state3", value = "状态3", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "state4", value = "状态4", required = false, dataType = "Integer")
    })
    public Map findRepay(@RequestParam("borrowName") String borrowName, @RequestParam("phone") String phone, @RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestParam("state1") String state1, @RequestParam("state2") String state2, @RequestParam("state3") String state3, @RequestParam("state4") String state4){
        List<Repayrecord> repay = repaymentService.findRepay(borrowName,  phone, page, size,state1,state2,state3,state4);
        Integer repayCount = repaymentService.findRepayCount(borrowName, phone, state1, state2, state3, state4);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(repay);
        jsonResult.put("count",repayCount);
        return jsonResult.getDataMap();
    }

}